﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Password</title>
</head>
<body>
    <form class="layui-form" action="" onsubmit="return false">
        <input type="hidden" value="@ViewBag.A.id" id="id" />
        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-block">
                <input type="password" id="OldPassword" required lay-verify="required" placeholder="请输入原密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" id="NewPassword" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" id="AgainPassword" required lay-verify="required" placeholder="请输入确认密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>layui.use(['form'], function () {
            var form = layui.form;
            var $ = layui.$;

            //监听提交
            form.on('submit(formDemo)', function (data) {
                //两次密码输入是否一致
                if ($("#NewPassword").val() != $("#AgainPassword").val()) {
                    layer.msg("两次密码输入是否一致");
                    return;
                }
                $.ajax({
                    url: "/Admin/DealPwd",//修改密码
                    type: "post",
                    data: {
                        id: $("#id").val(),
                        OldPassword: $("#OldPassword").val(),
                        NewPassword: $("#NewPassword").val(),

                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg)
                            //刷新当前页面
                            window.location.reload()
                        } else {
                            layer.msg(res.msg)
                        }
                    }
                })
                return false;
            });
        })</script>
</body>
</html>
